﻿using System.Collections.Generic;
using System.Windows;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml which is the startup window for the admin application
    /// </summary>
    public partial class MainWindow : Window
    {
        private static List<Assignment> assignments;

        public MainWindow()
        {
            InitializeComponent();    
            assignments = Queries.GetAssignments();
            dataGrid1.ItemsSource = assignments;
        }

        /// <summary>
        /// Creates a new step1 window that will start the process of creating a new assignment
        /// </summary>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var step1 = new Window1();
            step1.Show();
        }

        /// <summary>
        /// Deletes the row selected in the datagrid and deletes the assignment with everything linked to that 
        /// assignment from the database.
        /// </summary>
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if(dataGrid1.SelectedIndex >= 0)
            {
            var selectedObject = dataGrid1.SelectedItem as Assignment;
            int i = selectedObject.Id;
            Queries.DeleteAssignment(i);
            assignments.RemoveAt(dataGrid1.SelectedIndex);
            dataGrid1.Items.Refresh();
            }
        }

        /// <summary>
        /// Gets the selected assignment object out from the datagrid and creates a check assignment window 
        /// with a integer parameter equal to that of the assignment id.
        /// </summary>
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid1.SelectedIndex >= 0)
            {
                var checkAssignment = new CheckAssignment();
                var selectedObject = dataGrid1.SelectedItem as Assignment;
                int i = selectedObject.Id;
                checkAssignment.AssignmentInt = i;
                checkAssignment.setInfo();
                checkAssignment.Show();
            }
        }

        /// <summary>
        /// Help button showing a messagebox
        /// </summary>
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Tabellen i midten viser alle opgaver der er oprettet i øjeblikket." +
                            System.Environment.NewLine +
                            "Man kan vælge en af disse opgaver og derefter trykke på enten slet eller vis knappen." +
                            System.Environment.NewLine +
                            System.Environment.NewLine +
                            "Slet knappen sletter opgaven fra systemet så elever ikke kan finde den mere." +
                            System.Environment.NewLine +
                            System.Environment.NewLine +
                            "Vis knappen åbner et nyt vindue der viser alt information om opgaven" +
                            System.Environment.NewLine +
                            System.Environment.NewLine +
                            "Den sidste knap bruges hvis du ønsker at oprette en ny opgave.");
        }
    }
}
